<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建整改通知</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>整改通知编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">关联巡检</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="xunid" class="layui-input xunid" onclick="choose_engin_xun()">
                            <div class="choose_div" id="xunid" key="1"></div>
                            <span class="choose_one" onclick="choose_engin_xun()"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>整改负责人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=fuzeer&type=user&single=2', '770px', '490px');"></div>
                                <div class="tanxiannei" id="fuzeer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=fuzeer&type=user&single=2', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="fuzeer_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text><text>!</text>要求整改期限</label>
                        <div class="layui-input-block">
                            <input type="text" name="dt" id="dt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>复检人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=fujianer&type=user&single=1', '770px', '490px');"></div>
                                <div class="tanxiannei" id="fujianer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=fujianer&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="fujianer_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item height_auto" id="listDiv">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>需整改的问题</span></div>
                        <div>
                            <button type="button" onclick="ctrlv_data_open()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">粘贴新增</button>
                            <button type="button" onclick="choose_engin_xun_list()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">从巡检明细导入</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>检查项类别</th>
                            <th><text>*</text>检查项</th>
                            <th>说明</th>
                            <th>现场图片</th>
                            <th>整改措施</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>






    </div>
</form>
<script>


    $("#commentForm").validate({
        rules: {
            dt: {required: true},
        },
        messages:{
            dt: {required: "请选择"},
        }
    });



    function choose_engin_xun(){
        var enginid = get_choose_val('enginid');
        if(!enginid){
            facade.error("请先选择项目名称");return false;
        }
        openPage('../public/choose_engin_xun.php?page=engin_zheng&dom=xunid&enginid='+enginid,'80%','80%')
    }


    function choose_engin_xun_list() {
        var xunid = get_choose_val('xunid');
        if(!xunid){
            facade.error("请先选择关联巡检");return false;
        }
        openPage('../public/choose_engin_xun_list.php?page=engin_zheng&xunid='+xunid,'80%','80%');
    }




    function callback_add_list(data){
        var nums = $("#list_list tr").length;
        for (var key in data){
            nums++;
            var str = '';
            str += '<tr>';
            str += '<td style="width: 45px">'+nums+'</td>';
            str += '<td><input type="text" class="layui-input jiantype" value="'+data[key].jiantype+'"></td>';
            str += '<td><input type="text" class="layui-input name" value="'+data[key].name+'"></td>';
            str += '<td><input type="text" class="layui-input shuo"></td>';
            str += '<td>'+public_show_file_deta('list_list', data[key].filearr,1)+'</td>';
            str += '<td><input type="text" class="layui-input gaicon" value="'+data[key].gaicon+'"></td>';
            str += '</tr>';
            $("#list_list").append(str);
        }
        update_refresh_row_func();
    }


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_zheng_add}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#number").val(data.number);


                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><input type="text" class="layui-input jiantype"></td>';
                listAddStr += '<td><input type="text" class="layui-input name"></td>';
                listAddStr += '<td><input type="text" class="layui-input shuo"></td>';
                listAddStr += '<td>'+public_show_file_deta('list_list', [],1)+'</td>';
                listAddStr += '<td><input type="text" class="layui-input gaicon"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 1);

                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });


        form.on('submit(add)', function(data){
            parseMoney(data);


            var validRes = $("#commentForm").valid();
            data.field.enginid = get_choose_val('enginid');
            formValid('enginid');
            if(data.field.enginid == undefined || !data.field.enginid){
                validRes = false;
            }

            data.field.xunid = get_choose_val('xunid');
            data.field.fuzeer = tan_tags_getvalue("#fuzeer", 'user');
            if(!data.field.fuzeer){
                $("#fuzeer").parents('.tanxian').addClass('tanerror');
                $('#fuzeer_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#fuzeer").parents('.tanxian').removeClass('tanerror');
                $('#fuzeer_tanerror').text('');
            }
            data.field.fujianer = tan_tags_getvalue("#fujianer", 'user');
            if(!data.field.fujianer){
                $("#fujianer").parents('.tanxian').addClass('tanerror');
                $('#fujianer_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#fujianer").parents('.tanxian').removeClass('tanerror');
                $('#fujianer_tanerror').text('');
            }

            if(!validRes){return false;}


            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var jiantype = $(this).find('.jiantype').val();
                    var name = $(this).find('.name').val();
                    var shuo = $(this).find('.shuo').val();
                    var files = public_deta_file_value(this);
                    var gaicon = $(this).find('.gaicon').val();

                    var index = i + 1;
                    if(!name){
                        throw new Error('第'+index+'行，请输入检查项');
                    }

                    list.push({
                        jiantype:jiantype,
                        name:name,
                        shuo:shuo,
                        files:files,
                        gaicon:gaicon,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;


            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);
            facade.ajax({url: ask_engin_zheng_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });



    var ctrlv_field_name = [
        {field: 'jiantype', name:'检查项类别'},
        {field: 'name', name:'检查项'},
        {field: 'shuo', name:'说明'},
        {field: 'gaicon', name:'整改措施'},
    ];
    function ctrlv_data_show(list) {
        if(list.length > 0){
            var nums = $("#list_list tr").length;
            for (var key in list){
                var str = '';
                nums++;
                str += '<tr>';
                str += '<td style="width: 45px">'+nums+'</td>';
                str += '<td><input type="text" class="layui-input jiantype" value="'+list[key].jiantype+'"></td>';
                str += '<td><input type="text" class="layui-input name" value="'+list[key].name+'"></td>';
                str += '<td><input type="text" class="layui-input shuo" value="'+list[key].shuo+'"></td>';
                str += '<td>'+public_show_file_deta('list_list', [], 1)+'</td>';
                str += '<td><input type="text" class="layui-input gaicon" value="'+list[key].gaicon+'"></td>';
                str += '</tr>';
                $("#list_list").append(str);
            }
        }
        render_date();
        render_from();
    }

</script>
</body>
</html>
